package com.illtamer.infinite.sillage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.illtamer.infinite.sillage.service.BlogService;
import com.illtamer.infinite.sillage.service.TagService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

@Controller
@RequestMapping("/tags")
public class TagController {

    @Resource(name = "tagService")
    private TagService tagService;

    @Resource(name = "blogService")
    private BlogService blogService;

    @RequestMapping
    public String tags(@RequestParam(name = "index", required = false, defaultValue = "1") Integer index,
                       @RequestParam(name = "tagId", required = false, defaultValue = "1") Integer tagId,
                       Model model) {
        model.addAttribute("tags", tagService.listThinTags())
                .addAttribute("pages", blogService.listHomeBlogByTagId(index, 10, tagId))
                .addAttribute("tagId", tagId);
        return "tags";
    }



}
